import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/**
 * 重写路由的push方法
 */
/*  const routerPush = Router.prototype.push
 Router.prototype.push = function push(location) {
   return routerPush.call(this, location).catch(error=> error)
 }
 */
import Layout from "@/layout";
import webLayout from "@/webLayout";

import projectIcon from "@/assets/icon/project.png";
import supplierIcon from "@/assets/icon/supplier.png";
import supplierApproveIcon from "@/assets/icon/supplier_approve.png";
import supplierCategoryIcon from "@/assets/icon/supplier_category.png";
import supplierEvaluateIcon from "@/assets/icon/supplier_evaluate.png";
import supplierExampleIcon from "@/assets/icon/supplier_example.png";
import supplierNoticeIcon from "@/assets/icon/supplier_notice.png";
import supplierPoolIcon from "@/assets/icon/supplier_pool.png";
import supplierRejectionIcon from "@/assets/icon/supplier_rejection.png";
import supplierWebsiteIcon from "@/assets/icon/website.png";

export const historyRoutes = [
  {
    path: "/workbench",
    component: Layout,
    key: "0-2",
    name: "homeCode",
    parent: 0,
    meta: { title: "工作台", icon: "el-icon-s-home" },
    redirect: "/work",
    children: [
      {
        path: "/work",
        key: "0-2",
        meta: { title: "工作台", icon: "el-icon-s-home" },
        component: () => import("@/views/sys_home")
      }
    ]
  }
];

export const supplierRoutes = [
  {
    path: "/worksupplierbench",
    component: Layout,
    key: "0-3",
    name: "supplierbenchCode",
    parent: 0,
    meta: { title: "工作台", icon: "el-icon-s-home" },
    redirect: "/supplierbench",
    children: [
      {
        path: "/supplierbench",
        name: "supplierbenchCode",
        key: "0-3",
        meta: { title: "工作台", icon: "el-icon-s-home" },
        component: () => import("@/views/supplier_home")
      }
    ]
  }
];

export const constantRoutes = [
  {
    path: "/login",
    key: "-1",
    name: "loginCode",
    component: () => import("@/views/login"),
    meta: { title: "登陆", icon: "el-icon-setting" },
    hidden: true
  },
  //  {
  //    path: "/loginPage",
  //    key: "-2",
  //    name: "loginPage",
  //    component: () => import("@/webLayout/LoginPage"),
  //    meta: { title: "登陆", icon: "el-icon-setting" },
  //    hidden: true
  //  },
  /*   {
           path: "/material",
           name: "materialCode",
           key: "2",
           parent: 0,
           component: Layout,
           meta: { title: "物资管理", icon: "el-icon-setting" },
           children: [
             {
               path: "/material/list",
               name: "materialListCode",
               key: "2-1",
               meta: { title: "物资列表" },
               component: () => import("@/views/material/material_list")
             },
             {
               path: "/material/classify",
               name: "materialClassifyCode",
               key: "2-2",
               meta: { title: "物资分类列表" },
               component: () =>
                 import("@/views/material/material_classify_list")
             }
           ]
         },
         {
           path: "/labour",
           name: "labourCode",
           key: "3",
           parent: 0,
           component: Layout,
           meta: { title: "劳务管理", icon: "el-icon-setting" },
           children: [
             {
               path: "/labour/majorSubpackage",
               name: "labourMajorSubpackageCode",
               key: "3-1",
               meta: { title: "专业分包列表" },
               component: () =>
                 import("@/views/labour/labour_majorSubpackage_list")
             },
             {
               path: "/labour/subpackage",
               name: "labourSubpackageCode",
               key: "3-2",
               meta: { title: "劳务分包列表" },
               component: () => import("@/views/labour/labour_subpackage_list")
             }
           ]
         },*/
  {
    path: "/boardbench",
    component: Layout,
    key: "0-1",
    name: "boardCode",
    parent: 0,
    meta: { title: "看板", icon: "el-icon-s-home" },
    redirect: "/board",
    children: [
      {
        path: "/board",
        key: "0-1",
        name: "boardSubCode",
        meta: { title: "看板", icon: "el-icon-s-home" },
        component: () => import("@/views/board/index")
      }
    ]
  },
  {
    path: "/supplier/approve",
    name: "supplierApproveCode",
    key: "12",
    parent: 0,
    component: Layout,
    meta: { title: "供应商审核", icon: supplierApproveIcon },
    children: [
      {
        path: "/supplier/approve/reg",
        name: "supplierApproveRegCode",
        key: "12-1",
        meta: { title: "注册申请列表" },
        component: () => import("@/views/supplier/approve/reg")
      },
      {
        path: "/supplier/approve/store",
        name: "supplierApproveStoreCode",
        key: "12-2",
        meta: { title: "入库申请列表" },
        component: () => import("@/views/supplier/approve/store")
      },
      {
        path: "/supplier/approve/info",
        name: "supplierApproveInfoCode",
        key: "12-3",
        meta: { title: "资料更新列表" },
        component: () => import("@/views/supplier/approve/info")
      }
    ]
  },
  {
    path: "/supplier/rejection",
    name: "supplierRejection",
    key: "16",
    parent: 0,
    component: Layout,
    meta: { title: "驳回原因管理", icon: supplierRejectionIcon },
    children: [
      {
        path: "/supplier/rejection/reg",
        name: "supplierRejectionRegCode",
        key: "16-1",
        meta: { title: "注册驳回配置" },
        component: () => import("@/views/supplier/rejection/reg_reject")
      },
      {
        path: "/supplier/rejection/store",
        name: "supplierRejectionStoreCode",
        key: "16-2",
        meta: { title: "入库驳回配置" },
        component: () => import("@/views/supplier/rejection/store_reject")
      }
    ]
  },
  {
    path: "/supplier/pool",
    name: "supplierPoolCode",
    key: "11",
    parent: 0,
    component: Layout,
    meta: { title: "供应商公共池", icon: supplierPoolIcon },
    children: [
      {
        path: "/supplier/public/pool",
        name: "supplierPublicPoolCode",
        key: "11-1",
        meta: { title: "公共池" },
        component: () => import("@/views/supplier/supplier_pool_list")
      }
    ]
  },
  {
    path: "/supplier/category",
    name: "supplierCategoryCode",
    key: "13",
    parent: 0,
    component: Layout,
    meta: { title: "供应商分类设置", icon: supplierCategoryIcon },
    children: [
      {
        path: "/supplier/category/list",
        name: "supplierCategoryListCode",
        key: "13-1",
        meta: { title: "分类列表" },
        component: () => import("@/views/supplier/supplier_category")
      }
    ]
  },
  {
    path: "/supplier",
    name: "supplierCode",
    key: "10",
    parent: 0,
    component: Layout,
    meta: { title: "供应商动态管理", icon: supplierIcon },
    children: [
      {
        path: "/supplier/lib/pass",
        name: "supplierLibPassCode",
        key: "10-1",
        meta: { title: "合格列表" },
        component: () => import("@/views/supplier/lib/pass")
      },
      {
        path: "/supplier/lib/pause",
        name: "supplierLibPauseCode",
        key: "10-2",
        meta: { title: "暂停列表" },
        component: () => import("@/views/supplier/lib/pause")
      },
      {
        path: "/supplier/lib/blacklist",
        name: "supplierLibBlacklistCode",
        key: "10-3",
        meta: { title: "黑名单列表" },
        component: () => import("@/views/supplier/lib/blacklist")
      }
    ]
  },
  {
    path: "/supplier/evaluate",
    name: "supplierEvaluateCode",
    key: "15",
    parent: 0,
    component: Layout,
    meta: { title: "考核评分管理", icon: supplierEvaluateIcon },
    children: [
      {
        path: "/supplier/evaluate/building",
        name: "supplierEvaluateBuildingCode",
        key: "15-1",
        meta: { title: "工程和货物类" },
        component: () => import("@/views/supplier/evaluate/building")
      },
      {
        path: "/supplier/evaluate/property",
        name: "supplierEvaluatePropertyCode",
        key: "15-2",
        meta: { title: "服务类" },
        component: () => import("@/views/supplier/evaluate/property")
      },
      {
        path: "/supplier/evaluate/ledger",
        name: "supplierEvaluateLedgerCode",
        key: "15-3",
        meta: { title: "评审台帐列表" },
        component: () => import("@/views/supplier/evaluate/ledger")
      }
    ]
  },
  {
    path: "/project",
    name: "projectCode",
    key: "4",
    parent: 0,
    component: Layout,
    meta: { title: "项目库管理", icon: projectIcon },
    children: [
      {
        path: "/project/list",
        name: "projectListCode",
        key: "4-1",
        meta: { title: "项目库列表" },
        component: () => import("@/views/project/project_list")
      }
    ]
  },
  /*   {
           path: "/purchase",
           name: "purchaseCode",
           key: "5",
           parent: 0,
           component: Layout,
           meta: { title: "物资招标管理", icon: "el-icon-setting" },
           children: [
             {
               path: "/purchase/plan",
               name: "purchasePlanCode",
               key: "5-1",
               meta: { title: "物资采购计划" },
               component: () => import("@/views/purchase/purchase_plan_list")
             },
             {
               path: "/purchase/send",
               name: "purchaseSendCode",
               key: "5-5",
               meta: { title: "物资招标发起" },
               component: () => import("@/views/purchase/purchase_send_list")
             },
             {
               path: "/purchase/inquiry",
               name: "purchaseInquiryCode",
               key: "5-2",
               meta: { title: "询价招标列表" },
               component: () => import("@/views/purchase/purchase_inquiry_list")
             },
             {
               path: "/purchase/invitation",
               name: "purchaseInvitationCode",
               key: "5-3",
               meta: { title: "邀请招标列表" },
               component: () =>
                 import("@/views/purchase/purchase_invitation_list")
             },
             {
               path: "/purchase/overt",
               name: "purchaseOvertCode",
               key: "5-4",
               meta: { title: "公开招标列表" },
               component: () => import("@/views/purchase/purchase_overt_list")
             }
           ]
         },
         {
           path: "/labourPurchase",
           name: "labourPurchaseCode",
           key: "6",
           parent: 0,
           component: Layout,
           meta: { title: "劳务招标管理", icon: "el-icon-setting" },
           children: [
             {
               path: "/labourPurchase/plan",
               name: "labourPurchasePlanCode",
               key: "6-1",
               meta: { title: "劳务采购计划" },
               component: () =>
                 import("@/views/labourPurchase/labour_plan_list")
             },
             {
               path: "/labourPurchase/send",
               name: "labourPurchaseSendCode",
               key: "6-2",
               meta: { title: "劳务招标发起" },
               component: () =>
                 import("@/views/labourPurchase/labour_send_list")
             },
             {
               path: "/labourPurchase/invitation",
               name: "labourPurchaseInvitationCode",
               key: "6-3",
               meta: { title: "邀请招标列表" },
               component: () =>
                 import("@/views/labourPurchase/labour_invitation_list")
             },
             {
               path: "/labourPurchase/overt",
               name: "labourPurchaseOvertCode",
               key: "6-4",
               meta: { title: "公开招标列表" },
               component: () =>
                 import("@/views/labourPurchase/labour_overt_list")
             }
           ]
         },
         {
           path: "/contract",
           name: "contractCode",
           key: "7",
           parent: 0,
           component: Layout,
           meta: { title: "合同管理", icon: "el-icon-setting" },
           children: [
             {
               path: "/contract/material/list",
               name: "contractMaterialListCode",
               key: "7-1",
               meta: { title: "物资合同列表" },
               component: () =>
                 import("@/views/contract/contract_material_list")
             },
             {
               path: "/contract/labour/list",
               name: "contractLabourListCode",
               key: "7-2",
               meta: { title: "劳务合同列表" },
               component: () => import("@/views/contract/contract_labour_list")
             }
           ]
         },
         {
           path: "/deliver",
           name: "deliverCode",
           key: "8",
           parent: 0,
           component: Layout,
           meta: { title: "发货管理", icon: "el-icon-setting" },
           children: [
             {
               path: "/deliver/list",
               name: "deliverListCode",
               key: "8-1",
               meta: { title: "发货列表" },
               component: () => import("@/views/deliver/deliver_list")
             },
             {
               path: "/deliver/receiving",
               name: "deliverReceivingCode",
               key: "8-2",
               meta: { title: "收货列表" },
               component: () => import("@/views/deliver/deliver_receiving_list")
             }
           ]
         },
          */
  /*
         {
               path: "/supplier/material/list",
               name: "supplierMaterialListCode",
               key: "10-1",
               meta: { title: "物资供应商列表" },
               component: () =>
                 import("@/views/supplier/supplier_material_list")
             },
             {
               path: "/supplier/labour/list",
               name: "supplierLabourListCode",
               key: "10-2",
               meta: { title: "劳务供应商列表" },
               component: () => import("@/views/supplier/supplier_labour_list")
             },
             {
               path: "/supplier/qutside/list",
               name: "supplierQutsideListCode",
               key: "10-3",
               meta: { title: "游客列表" },
               component: () => import("@/views/supplier/supplier_qutside_list")
             }
         */
  {
    path: "/supplier/notice",
    name: "supplierNoticeCode",
    key: "14",
    parent: 0,
    component: Layout,
    meta: { title: "通知公告管理", icon: supplierNoticeIcon },
    children: [
      {
        path: "/supplier/notice/list",
        name: "supplierNoticeListCode",
        key: "14-1",
        meta: { title: "通知公告列表" },
        component: () => import("@/views/supplier/notice/list")
      },
      {
        path: "/supplier/notice/classfiy",
        name: "supplierNoticeClassfiyCode",
        key: "14-2",
        meta: { title: "分类管理" },
        component: () => import("@/views/supplier/notice/classfiy")
      }
    ]
  },
  {
    path: "/supplier/example",
    name: "supplierExampleCode",
    key: "17",
    parent: 0,
    component: Layout,
    meta: { title: "示例管理", icon: supplierExampleIcon },
    children: [
      {
        path: "/supplier/example/file",
        name: "supplierExampleFileCode",
        key: "17-1",
        meta: { title: "入库附件示例" },
        component: () => import("@/views/supplier/example/store_file_example")
      }
    ]
  },
  {
    path: "/website",
    name: "websiteCode",
    key: "9",
    parent: 0,
    component: Layout,
    meta: { title: "网站管理", icon: supplierWebsiteIcon },
    children: [
      /* 
              {
                path: '/website/picture',
                name:'websitePictureCode',
                key:'9-2',
                meta: { title: '图片列表' },
                component: () => import('@/views/website/website_picture_list'),
              },
              */
      {
        path: "/website/about",
        name: "websiteAboutCode",
        key: "9-1",
        meta: { title: "关于我们" },
        component: () => import("@/views/website/website_about_list")
      },
      {
        path: "/website/customInfo",
        name: "websiteCustomInfoCode",
        key: "9-2",
        meta: { title: "自定义内容" },
        component: () => import("@/views/website/website_info_list")
      },
      {
        path: "/website/news",
        name: "websiteNewsCode",
        key: "9-3",
        meta: { title: "新闻列表" },
        component: () => import("@/views/website/website_news_list")
      }
    ]
  },
  {
    path: "/system",
    name: "systemCode",
    key: "1",
    parent: 0,
    component: Layout,
    meta: { title: "系统设置", icon: "el-icon-setting" },
    children: [
      {
        path: "/system/supplier",
        name: "systemSupplierCode",
        key: "1-0",
        meta: { title: " 供应商账号管理" },
        component: () => import("@/views/system/supplier_list")
      },
      {
        path: "/system/user",
        name: "systemUserCode",
        key: "1-1",
        meta: { title: " 用户管理" },
        component: () => import("@/views/system/system_user_list")
      },
      {
        path: "/system/role",
        name: "systemRoleCode",
        key: "1-2",
        meta: { title: "角色管理" },
        component: () => import("@/views/system/system_role_list")
      },
      //  {
      //    path: "/system/permission",
      //    name: "systemPermissionCode",
      //    key: "1-3",
      //    meta: { title: "权限管理" },
      //    component: () => import("@/views/system/system_permission_list")
      //  },
      // {
      //   path: "/system/node",
      //   name: "systemNodeCode",
      //   key: "1-4",
      //   meta: { title: "工作流配置" },
      //   component: () => import("@/views/system/system_node_list")
      // },
      {
        path: "/system/department",
        name: "systemDepartmentCode",
        key: "1-5",
        meta: { title: "部门管理" },
        component: () => import("@/views/system/system_department_list")
      },
      {
        path: "/system/position",
        name: "systemPositionCode",
        key: "1-6",
        meta: { title: "职位管理" },
        component: () => import("@/views/system/system_position_list")
      },
      {
        path: "/system/dataLog",
        name: "systemDataLogCode",
        key: "1-7",
        meta: { title: "数据日志" },
        component: () => import("@/views/system/system_dataLog_list")
      },
      {
        path: "/system/operationLog",
        name: "systemOperationLogCode",
        key: "1-8",
        meta: { title: "操作日志" },
        component: () => import("@/views/system/system_operationLog_list")
      }
    ]
  },
  {
    path: "/supplier/my",
    name: "supplierMyCode",
    key: "18",
    parent: 0,
    component: Layout,
    meta: { title: "功能菜单", icon: "el-icon-setting" },
    children: [
      {
        path: "/supplier/my/category",
        name: "supplierMyCategoryCode",
        key: "18-1",
        meta: { title: "入库类别列表" },
        component: () => import("@/views/supplier/my/category_list")
      },
      {
        path: "/supplier/my/notice",
        name: "supplierMyNoticeCode",
        key: "18-2",
        meta: { title: "通知公告列表" },
        component: () => import("@/views/supplier/my/notice_list")
      },
      {
        path: "/supplier/my/ledger",
        name: "supplierMyLedgerCode",
        key: "18-3",
        meta: { title: "评价列表" },
        component: () => import("@/views/supplier/my/ledger_list")
      }
    ]
  }
];

export const webRoutes = [
  {
    path: "/",
    key: "-2",
    name: "webCode",
    component: webLayout,
    redirect: "/web/home",
    children: [
      {
        path: "/web/home",
        name: "webHomeCode",
        component: () => import("@/views/web/home")
      },
      {
        path: "/web/inquiry",
        name: "webInquiryCode",
        component: () => import("@/views/web/inquiry")
      },
      {
        path: "/web/invitation",
        name: "webInvitationCode",
        component: () => import("@/views/web/invitation")
      },
      {
        path: "/web/overt",
        name: "webOvertCode",
        component: () => import("@/views/web/overt")
      },
      {
        path: "/web/news",
        name: "webNewsCode",
        component: () => import("@/views/web/news")
      },
      {
        path: "/web/newsDetails",
        name: "webNewsDetailsCode",
        component: () => import("@/views/web/news_details")
      },
      {
        path: "/web/notice",
        name: "webNoticeCode",
        component: () => import("@/views/web/notice")
      },
      {
        path: "/web/reg",
        name: "webRegCode",
        component: () => import("@/views/web/reg")
      },
      {
        path: "/web/about",
        name: "webAboutCode",
        component: () => import("@/views/web/about")
      }
    ]
  }
];
// hash history
const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    mode: "hash",
    routes: [
      ...historyRoutes,
      ...supplierRoutes,
      ...constantRoutes,
      ...webRoutes
    ]
  });

const router = createRouter();

// 定义一个resetRouter 方法，在退出登录时，调用即可
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher;
}

export default router;
